package com.net.shop.car.manager.api.volley.response.dingdan;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.net.shop.car.manager.api.model.OilCardDingDan;
import com.net.shop.car.manager.api.volley.Response;
import com.net.shop.car.manager.utils.Constants;
import com.net.shop.car.manager.utils.StringUtils;

public class DingdanOilCardListResponse extends Response {

	private int totalPages;
	private List<OilCardDingDan> oilCardDingDans;
	
	public DingdanOilCardListResponse() {
		super(Constants.DINGDAN_CARDORDER_LIST);
	}
	
	@Override
	public String[] getContentTags() {
		return new String[]{"totalpages","orderlist"};
	}
	@Override
	public void parseContent(String content, int index) {
		if (index == 0) {
			totalPages = StringUtils.filterIntegerNull(content);
		} else if (index == 1) {
			JSONArray jsonArray;
			try {
				jsonArray = new JSONArray(content);
				oilCardDingDans = new ArrayList<OilCardDingDan>();
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject jsonObject = jsonArray.getJSONObject(i);
					OilCardDingDan dingDan = new OilCardDingDan();
					dingDan.setCreateDate(StringUtils.filterNull(jsonObject.getString("CREATE_DATE")));
					dingDan.setGoodName(StringUtils.filterNull(jsonObject.getString("GOODNAME")));
					dingDan.setId(StringUtils.filterNull(jsonObject.getString("ID")));
					dingDan.setOilCardNum(StringUtils.filterNull(jsonObject.getString("OIL_CARD_NUM")));
					dingDan.setVb(StringUtils.filterLongNull(jsonObject.getString("VB")));
					dingDan.setChongzhiState(StringUtils.filterIntegerNull(jsonObject.getString("CHONGZHI_STATE")));
					oilCardDingDans.add(dingDan);
				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	

	public int getTotalPages() {
		return totalPages;
	}

	/**
	 * @return the oilCardDingDans
	 */
	public List<OilCardDingDan> getOilCardDingDans() {
		return oilCardDingDans;
	}
	
}
